### The GIM root directory
GIMDIR = ../../..
OPTS = 
CC=gcc
CXX=g++
LNMDIR=$(GIMDIR)/LnMlib/src

CFLAGS=-Wall $(DEBUG) $(DEFINITIONS) $(CINCLUDES) $(CMISCFLAGS) $(LIBDIRS) $(OPTS) `xml2-config --cflags`
CPPFLAGS=-Wall  $(DEBUG) $(EXCEPTIONS) $(CPPINCLUDES) \
				$(DEFINITIONS) $(CPPMISCFLAGS) $(LIBDIRS) $(OPTS)
DEBUG=-O0 -g3
CMISCFLAGS=
CPPMISCFLAGS=
DEFINITIONS=-DLINUX_OS -D_GNU_SOURCE -DOS_LINUX -Duse_namespace

EXCEPTIONS=-fexceptions

UTILS_DIR = $(GIMDIR)/utils

CINCLUDES=$(ILINK_INCLUDE) -I$(UTILS_DIR) $(NEWMAT_INC)
CPPINCLUDES=$(ILINK_INCLUDE) -I$(UTILS_DIR) $(NEWMAT_INC)
LIBDIRS=

LD=g++
LDFLAGS=$(LIBDIRS)

LIBS=-lrt -lm -lpthread

UTILS_SRC = $(GIMDIR)/utils/ownutils.c

SRCSC=$(ILINK_SRC_C) $(UTILS_SRC)
SRCSCPP=$(ILINK_SRC_CPP)
VPATH=


include $(GIMDIR)/MaCI/drivers/IMU/Inertial-Link/Makefile.ilink
include $(LNMDIR)/extlib/newmat/Makefile.newmat
## Construct final lists of CPP and C objects
OBJSC=$(SRCSC:.c=.o)
OBJSCPP=$(SRCSCPP:.cpp=.opp)
OBJNEWMAT=$(CPP_NEWMAT:.cpp=.opp)

## Define compiles and links
COMPILEC=$(CC) $(CFLAGS) $(CINCLUDES) -c
COMPILECPP=$(CXX) $(CPPFLAGS) $(CPPINCLUDES) -c
LINK=$(LD) $(LDFLAGS) $(LIBS)

.PHONY: all clean

all: test
	
##witbin: $(OBJSC) $(OBJSCPP)

test: $(OBJSC) $(OBJSCPP) $(OBJNEWMAT) rt-tester.opp
			$(LINK) -o $@ $(OBJSC) $(OBJSCPP) $(OBJNEWMAT) rt-tester.opp
							
clean:
	rm -f $(OBJSC) $(OBJSCPP) ilink *.out *~ *.d *.dpp

##manual:
##	doxygen

## Compile rule for all .o (.c) file
%.o:    %.c
				$(COMPILEC) -o $@ $<

## Compile rule for all .opp (.cpp) files
%.opp:	%.cpp
				$(COMPILECPP) -o $@ $<

## Dependency generation rule: For all required '.d' files
%.d:	  %.c
				$(CC) -MM $(CFLAGS) $< > $@.$$$$; \
				sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
				rm -f $@.$$$$

